package com.gzx.plugin.tjzy.modular.complaint.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gzx.plugin.tjzy.modular.complaint.entity.bo.GzxComplaintUserAddOrEditBo;
import com.gzx.plugin.tjzy.modular.complaint.entity.bo.GzxComplaintUserDeleteBo;
import com.gzx.plugin.tjzy.modular.complaint.entity.bo.GzxComplaintUserQueryBo;
import com.gzx.plugin.tjzy.modular.complaint.entity.vo.GzxComplaintUserVo;
import com.gzx.plugin.tjzy.modular.complaint.service.GzxComplaintUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.annotation.CommonNoRepeat;
import vip.xiaonuo.common.pojo.CommonResult;

import java.util.ArrayList;
import java.util.List;

/**
 * 投诉用户信息
 * 前端访问路由地址为:/tjzy/complaint
 *
 * @author LionLi
 * @date 2024-10-09
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/tjzy/complaint")
public class GzxComplaintUserController {

    private final GzxComplaintUserService complaintUserService;

    /**
     * 查询投诉用户信息列表
     */
    @PostMapping("/pageList")
    public CommonResult<Page<GzxComplaintUserVo>> pageList(@RequestBody GzxComplaintUserQueryBo complaintUserQueryBo) {
        return CommonResult.data(complaintUserService.pageList(complaintUserQueryBo));
    }

    @GetMapping("/checkComplaintUser")
    public CommonResult<List<String>> checkComplaintUser(@RequestParam("idCardList") List<String> idCardList) {
        return CommonResult.data(complaintUserService.checkComplaintUser(idCardList));
    }

    @PostMapping("/add")
    public CommonResult<String> add(@RequestBody GzxComplaintUserAddOrEditBo bo) {
        complaintUserService.add(bo);
        return CommonResult.ok();
    }

    @PostMapping("/edit")
    public CommonResult<String> edit(@RequestBody GzxComplaintUserAddOrEditBo bo) {
        complaintUserService.edit(bo);
        return CommonResult.ok();
    }

    @PostMapping("/delete")
    public CommonResult<String> delete(@RequestBody List<GzxComplaintUserDeleteBo> bos) {
        ArrayList<Long> ids = new ArrayList<>();
        for (GzxComplaintUserDeleteBo bo : bos) {
            ids.add(bo.getId());
        }
        complaintUserService.deleteWithValidByIds(ids, true);
        return CommonResult.ok();
    }

    /**
     * 客户一键拉黑
     *
     * @param complaintUserAddOrEditBo
     * @return
     */
    @CommonNoRepeat
    @PostMapping("/blackoutCustomers")
    public CommonResult<Void> blackoutCustomers(@RequestBody GzxComplaintUserAddOrEditBo complaintUserAddOrEditBo) {
        complaintUserService.blackoutCustomers(complaintUserAddOrEditBo);
        return CommonResult.ok();
    }

    @CommonLog("投诉用户批量导入")
    @PostMapping("/importExcel")
    public CommonResult<String> importExcel(@RequestParam("file") MultipartFile file) throws Exception {
        complaintUserService.importExcel(file);
        return CommonResult.ok();
    }
}
